final class DefaultWebClientBuilder extends java.lang.Object implements WebClient.Builder
WebClient.Builder
.Modifier and Type | Field and Description |
---|---|
private java.lang.String |
baseUrl |
private ClientHttpConnector |
connector |
private MultiValueMap<java.lang.String,java.lang.String> |
defaultCookies |
private HttpHeaders |
defaultHeaders |
private java.util.Map<java.lang.String,?> |
defaultUriVariables |
private ExchangeFunction |
exchangeFunction |
private ExchangeStrategies |
exchangeStrategies |
private java.util.List<ExchangeFilterFunction> |
filters |
private UriBuilderFactory |
uriBuilderFactory |
Constructor and Description |
---|
DefaultWebClientBuilder() |
DefaultWebClientBuilder(DefaultWebClientBuilder other) |
Modifier and Type | Method and Description |
---|---|
WebClient.Builder |
apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
Shortcut for pre-packaged customizations to WebTest builder.
|
WebClient.Builder |
baseUrl(java.lang.String baseUrl)
Configure a base URL for requests performed through the client.
|
WebClient |
build()
Builder the
WebClient instance. |
WebClient.Builder |
clientConnector(ClientHttpConnector connector)
Configure the
ClientHttpConnector to use. |
WebClient.Builder |
clone()
Clone this
WebClient.Builder |
WebClient.Builder |
defaultCookie(java.lang.String cookieName,
java.lang.String... cookieValues)
Add the given header to all requests that haven't added it.
|
WebClient.Builder |
defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
Manipulate the default cookies with the given consumer.
|
WebClient.Builder |
defaultHeader(java.lang.String headerName,
java.lang.String... headerValues)
Add the given header to all requests that have not added it.
|
WebClient.Builder |
defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
Manipulate the default headers with the given consumer.
|
WebClient.Builder |
defaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
Configure default URI variable values that will be used when expanding
URI templates using a
Map . |
WebClient.Builder |
exchangeFunction(ExchangeFunction exchangeFunction)
Provide a pre-configured
ExchangeFunction instance. |
WebClient.Builder |
exchangeStrategies(ExchangeStrategies strategies)
Configure the
ExchangeStrategies to use. |
WebClient.Builder |
filter(ExchangeFilterFunction filter)
Add the given filter to the filter chain.
|
WebClient.Builder |
filters(java.util.function.Consumer<java.util.List<ExchangeFilterFunction>> filtersConsumer)
Manipulate the filters with the given consumer.
|
private MultiValueMap<java.lang.String,java.lang.String> |
initCookies() |
private ExchangeFunction |
initExchangeFunction() |
private java.util.List<ExchangeFilterFunction> |
initFilters() |
private HttpHeaders |
initHeaders() |
private UriBuilderFactory |
initUriBuilderFactory() |
private static HttpHeaders |
unmodifiableCopy(HttpHeaders original) |
private static <K,V> MultiValueMap<K,V> |
unmodifiableCopy(MultiValueMap<K,V> original) |
WebClient.Builder |
uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configured
UriBuilderFactory instance. |
@Nullable private java.lang.String baseUrl
@Nullable private java.util.Map<java.lang.String,?> defaultUriVariables
@Nullable private UriBuilderFactory uriBuilderFactory
@Nullable private HttpHeaders defaultHeaders
@Nullable private MultiValueMap<java.lang.String,java.lang.String> defaultCookies
@Nullable private java.util.List<ExchangeFilterFunction> filters
@Nullable private ClientHttpConnector connector
@Nullable private ExchangeFunction exchangeFunction
private ExchangeStrategies exchangeStrategies
public DefaultWebClientBuilder()
public DefaultWebClientBuilder(DefaultWebClientBuilder other)
public WebClient.Builder baseUrl(java.lang.String baseUrl)
WebClient.Builder
For example given base URL "http://abc.com/v1":
Mono<Account> result = client.get() .uri("/accounts/{id}", 43) .exchange() .then(response -> response.bodyToMono(Account.class)); // Result: http://abc.com/v1/accounts/43 Flux<Account> result = client.get() .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) .exchange() .then(response -> response.bodyToFlux(Account.class)); // Result: http://abc.com/v1/accounts?q=12
The base URL can be overridden with an absolute URI:
Mono<Account> result = client.get() .uri("http://xyz.com/path") .exchange() .then(response -> response.bodyToMono(Account.class)); // Result: http://xyz.com/path
Or partially overridden with a UriBuilder
:
Flux<Account> result = client.get() .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) .exchange() .then(response -> response.bodyToFlux(Account.class)); // Result: http://abc.com/v2/accounts?q=12
baseUrl
in interface WebClient.Builder
WebClient.Builder.defaultUriVariables(Map)
,
WebClient.Builder.uriBuilderFactory(UriBuilderFactory)
public WebClient.Builder defaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
WebClient.Builder
Map
.defaultUriVariables
in interface WebClient.Builder
defaultUriVariables
- the default values to useWebClient.Builder.baseUrl(String)
,
WebClient.Builder.uriBuilderFactory(UriBuilderFactory)
public WebClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
WebClient.Builder
UriBuilderFactory
instance. This is
an alternative to and effectively overrides the following:
uriBuilderFactory
in interface WebClient.Builder
uriBuilderFactory
- the URI builder factory to useWebClient.Builder.baseUrl(String)
,
WebClient.Builder.defaultUriVariables(Map)
public WebClient.Builder defaultHeader(java.lang.String headerName, java.lang.String... headerValues)
WebClient.Builder
defaultHeader
in interface WebClient.Builder
headerName
- the header nameheaderValues
- the header valuespublic WebClient.Builder defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
WebClient.Builder
HttpHeaders
methods.defaultHeaders
in interface WebClient.Builder
headersConsumer
- a function that consumes the HttpHeaders
private HttpHeaders initHeaders()
public WebClient.Builder defaultCookie(java.lang.String cookieName, java.lang.String... cookieValues)
WebClient.Builder
defaultCookie
in interface WebClient.Builder
cookieName
- the cookie namecookieValues
- the cookie valuespublic WebClient.Builder defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
WebClient.Builder
MultiValueMap
methods.defaultCookies
in interface WebClient.Builder
cookiesConsumer
- a function that consumes the cookies mapprivate MultiValueMap<java.lang.String,java.lang.String> initCookies()
public WebClient.Builder clientConnector(ClientHttpConnector connector)
WebClient.Builder
ClientHttpConnector
to use.
By default an instance of
ReactorClientHttpConnector
is created if this is not set. However a
shared instance may be passed instead, e.g. for use with multiple
WebClient
's targeting different base URIs.
clientConnector
in interface WebClient.Builder
connector
- the connector to useWebClient.Builder.exchangeStrategies(ExchangeStrategies)
,
WebClient.Builder.exchangeFunction(ExchangeFunction)
public WebClient.Builder filter(ExchangeFilterFunction filter)
WebClient.Builder
filter
in interface WebClient.Builder
filter
- the filter to be added to the chainpublic WebClient.Builder filters(java.util.function.Consumer<java.util.List<ExchangeFilterFunction>> filtersConsumer)
WebClient.Builder
filters
in interface WebClient.Builder
filtersConsumer
- a function that consumes the filter listprivate java.util.List<ExchangeFilterFunction> initFilters()
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)
WebClient.Builder
ExchangeFunction
instance. This is
an alternative to and effectively overrides the following:
exchangeFunction
in interface WebClient.Builder
exchangeFunction
- the exchange function to useWebClient.Builder.clientConnector(ClientHttpConnector)
,
WebClient.Builder.exchangeStrategies(ExchangeStrategies)
public WebClient.Builder exchangeStrategies(ExchangeStrategies strategies)
WebClient.Builder
ExchangeStrategies
to use.
By default ExchangeStrategies.withDefaults()
is used.
exchangeStrategies
in interface WebClient.Builder
strategies
- the strategies to useWebClient.Builder.clientConnector(ClientHttpConnector)
,
WebClient.Builder.exchangeFunction(ExchangeFunction)
public WebClient build()
WebClient.Builder
WebClient
instance.build
in interface WebClient.Builder
@Nullable private static HttpHeaders unmodifiableCopy(@Nullable HttpHeaders original)
@Nullable private static <K,V> MultiValueMap<K,V> unmodifiableCopy(@Nullable MultiValueMap<K,V> original)
private UriBuilderFactory initUriBuilderFactory()
private ExchangeFunction initExchangeFunction()
public WebClient.Builder clone()
WebClient.Builder
WebClient.Builder
clone
in interface WebClient.Builder
clone
in class java.lang.Object
public WebClient.Builder apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
WebClient.Builder
apply
in interface WebClient.Builder
builderConsumer
- the consumer to apply